﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// Tab_1.xaml 的交互逻辑
    /// </summary>
    public partial class Tab_1 : Window
    {
        int i = 0;

        public Tab_1()
        {
            InitializeComponent();
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var menu = sender as MenuItem;
            switch (menu.Header)
            {
                case "Add":
                    var tabItem = new TabItem();
                    tabItem.Header = $"Tab Item {i++}";
                    tabItem.Background = new SolidColorBrush(Color.FromRgb((byte)new Random().Next(256), (byte)new Random().Next(256), (byte)new Random().Next(256)));
                    tab1.Items.Add(tabItem);
                    break;
                case "Clear":
                    tab1.Items.Clear();
                    i = 0;
                    break;
                default:
                    break;
            }
        }

        private void tab1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (tab1.SelectedItem == null)
                return;

            tab1.Background = ((TabItem)tab1.SelectedItem).Background;
        }
    }
}
